package com.strat.searcher.lucene.querry;

import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.search.Query;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.strat.searcher.exceptions.IndexingException;

public class QueryAnaliser {

    private final static String ERROR = "";
    private QueryParserWrappable wrapper = new QueryParserUnsupported();

    public QueryAnaliser(QueryParserWrappable wrapper) {
        this.wrapper = wrapper;
    }

    public QueryAnaliser() {

    }

    private static Logger logger = LoggerFactory.getLogger(QueryAnaliser.class);

    public Query analyse(String queryString) {
        if (queryString == null) {
            throw new IndexingException();
        }

        Query query;
        try {
            query = wrapper.getParser().parse(queryString);
            return query;
        } catch (ParseException e) {
            logger.error(ERROR, e);
            throw new IndexingException(ERROR, e);
        }
    }
}
